<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Druid Demo</title>
<!-- Bootstrap -->
<link href="webjars/bootstrap/3.3.1/css/bootstrap.min.css"
	rel="stylesheet">
<!-- <link href="webjars/bootstrap/3.3.1/css/bootstrap-theme.min.css"
	rel="stylesheet"> -->
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
      <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
	<div class="container-fluid">
		<div class="row">
			<div class="col-md-12">
				<h3>测试案例</h3>
			</div>
		</div>
		<!-- row1 end -->
		<div class="row">
			<div class="col-sm-4">
				<div class="panel panel-primary">
					<div class="panel-heading">
						<h3 class="panel-title">批量数据操作</h3>
					</div>
					<div class="panel-body">
						<ol>
							<li>插入100笔数据</li>
							<li>更新这些数据</li>
							<li>删除这些数据</li>
						</ol>
						<button id="but1" type="button" class="btn btn-sm btn-success"
							data-loading-text="执行中......">
							<span class="glyphicon glyphicon-play"></span>
						</button>
					</div>
				</div>
			</div>
			<div class="col-sm-4">
				<div class="panel panel-primary">
					<div class="panel-heading">
						<h3 class="panel-title">SQL注入攻击测试</h3>
					</div>
					<div class="panel-body">
						<textarea class="form-control" rows="3"></textarea>
						<button type="button" class="btn btn-sm btn-success">
							<span class="glyphicon glyphicon-play"></span>
						</button>
						<span class="alert alert-warning" role="alert">开发中，暂未实现...</span>
					</div>
				</div>
			</div>
			<div class="col-sm-4">
				<div class="panel panel-primary">
					<div class="panel-heading">
						<h3 class="panel-title">随机访问以下地址100次</h3>
					</div>
					<div class="panel-body">
						<ul>
							<li>URL1</li>
							<li>URL2</li>
							<li>URL3</li>
						</ul>
						<button type="button" class="btn btn-sm btn-success">
							<span class="glyphicon glyphicon-play"></span>
						</button>
						<span class="alert alert-warning" role="alert">开发中，暂未实现...</span>
					</div>
				</div>
			</div>
		</div>
		<!-- row2 end -->
	</div>
	<!-- container end -->

	<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
	<script src="webjars/jquery/1.11.1/jquery.min.js"></script>
	<!-- Include all compiled plugins (below), or include individual files as needed -->
	<script src="webjars/bootstrap/3.3.1/js/bootstrap.min.js"></script>
	<script src="js/jsonrpcjs-0.1.8.min.js"></script>
	<script>
		var testCount = 100;
		var rpc = new jsonrpc.JsonRpc("service/user");
		rpc.loading.bind(function() {
			rpc.button.button("loading");
		});
		rpc.loaded.bind(function() {
			rpc.button.button("reset");
		});

		$("#but1").click(function() {
			rpc.button = $(this);
			var result = [ 0, 0 ];
			//插入100笔数据
			for (var i = 0; i < testCount; i++) {
				rpc.call('addUser', {
					id : i + "",
					name : "User" + i,
					loginName : "U" + i,
					email : "U" + i + "@email.com"
				}, {
					success : function(r) {
						result[0] += r;
					},
					failure : function(reason) {
						result[1]++;
						console.log('Method call failed because of ' + reason);
					},
				});
			}
			//更新这些数据
			for (var i = 0; i < testCount; i++) {
				rpc.call('updateUser', {
					id : i + "",
					name : "UserUpdate" + i,
					loginName : "UU" + i,
					email : "UU" + i + "@email.com"
				}, {
					success : function(r) {
						result[0] += r;
					},
					failure : function(reason) {
						result[1]++;
						console.log('Method call failed because of ' + reason);
					},
				});
			}
			//删除这些数据
			for (var i = 0; i < testCount; i++) {
				rpc.call('deleteUser', i + "", {
					success : function(r) {
						result[0] += r;
					},
					failure : function(reason) {
						result[1]++;
						console.log('Method call failed because of ' + reason);
					},
				});
			}
		});
	</script>
</body>
</html>